const CracoLessPlugin = require('craco-less');
const path = require('path');
const pathResolve = pathUrl => path.join(__dirname, pathUrl);
const WebpackBar = require('webpackbar');
// 当前环境
const CURRENT_ENV = process.env.REACT_APP_ENV;

// 代理路径
const PROXY_URL = {
  dev: 'https://datlas.idatatlas.com/',
  staging: 'https://huamu2.metrodata.cn:10443/',
  prod: ''
};
const proxyUrl = PROXY_URL[CURRENT_ENV];
module.exports = {
  webpack: {
    configure: webpackConfig => {
      const scopePluginIndex = webpackConfig.resolve.plugins.findIndex(
        ({ constructor }) => constructor && constructor.name === 'ModuleScopePlugin'
      );

      webpackConfig.resolve.plugins.splice(scopePluginIndex, 1);
      return webpackConfig;
    },
    alias: {
      '@@': pathResolve('./node_modules/@datlas/design/esm'),
      '@': pathResolve('src'),
      react: pathResolve('./node_modules/react')
    },
    plugins: [new WebpackBar()]
  },
  plugins: [
    {
      plugin: CracoLessPlugin,
      options: {
        lessLoaderOptions: {
          lessOptions: {
            javascriptEnabled: true
          }
        }
      }
    }
  ],
  devServer: {
    port: 3300,
    proxy: [
      {
        context: ['/api'],
        target: proxyUrl,
        changeOrigin: true
      }
    ]
  }
};
